package com.maxatime.web.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.maxatime.common.constant.BusinessContents;
import com.maxatime.pojo.entity.tStudent2;
import com.maxatime.service.Homeser;
import com.maxatime.util.MyContent;

@Controller
@RequestMapping("/home")
public class Home {
	@Autowired
	Homeser homeser;
	
	 
	@RequestMapping("/quest")
	@ResponseBody
	public Map<String, Object> quest(@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		
		String studentName = jsonObj.getString("studentName");
		int pageNum = jsonObj.getIntValue("pageNum");
		int pageSize = jsonObj.getIntValue("pageSize");
		tStudent2 tstudent2 = new tStudent2();
		tstudent2.setStudentName(studentName);
		tstudent2.setPageNum(pageNum);
		tstudent2.setPageSize(pageSize);
		Map<String, Object> m = homeser.list(tstudent2);
		m.put(BusinessContents.CODE, "0000");
		m.put(BusinessContents.MSG, "交易成功");
		m.put(BusinessContents.DATA, m.get("list"));
		m.put("pageInfo", m.get("pageInfo"));
		return m;
	}
	
	@RequestMapping("/save")
	@ResponseBody
	public Map<String, Object> save(@RequestBody tStudent2 tstudent2){
		Map<String, Object> m = new HashMap<>();
		homeser.insertSelective(tstudent2);
		m.put(MyContent.CODE, "1111");
		m.put(MyContent.MSG, "新增成功");
		return m;
	}
	@RequestMapping("/delete")
	@ResponseBody
	public Map<String, Object> delete(@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		int studentNo = jsonObj.getInteger("studentNo");
		
		Map<String, Object> m = new HashMap<>();
		homeser.deleteByPrimaryKey(studentNo);
		m.put(MyContent.CODE, "2222");
		m.put(MyContent.MSG, "删除成功");
		return m;
	}
	@RequestMapping("/find")
	@ResponseBody
	public Map<String, Object> find (@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		int studentNo = jsonObj.getInteger("studentNo");
		
		Map<String, Object> m = new HashMap<>();
		tStudent2 tstudent2 = homeser.find(studentNo);
		m.put(MyContent.CODE, "3333");
		m.put(MyContent.MSG, "反显成功");
		m.put(MyContent.DATA, tstudent2);
		return m;
	}
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, Object> update (@RequestBody tStudent2 tstudent2){
		Map<String, Object> m = new HashMap<>();
		homeser.updateByPrimaryKeySelective(tstudent2);
		m.put(MyContent.CODE, "4444");
		m.put(MyContent.MSG, "修改成功");
	
		return m;
	}
	
	@RequestMapping("/ckstudentNo")
	@ResponseBody
	public Map<String, Object> ckstudentNo(@RequestBody tStudent2 tstudent2){
		Map<String, Object> m = new HashMap<>();
		
		tStudent2 tStudent1=homeser.ckstudentNo(tstudent2.getStudentNo());
		//System.out.println("adadww11112213213adadad"+tStudent1.getStudentName());
		m.put(MyContent.CODE, "5555");
		m.put(MyContent.MSG, "查看成功");
		m.put(MyContent.DATA, tStudent1);
		return m;
	}
	
}
